<?
require_once("dbdata.inc.php");
$db = mysql_connect($MySQLServer,$MySQLUsername,$MySQLPassword);
print (mysql_error());
mysql_select_db($MySQLDB,$db);
print (mysql_error());

$result = mysql_query("SELECT name FROM bots WHERE id='$botid';",$db);
print (mysql_error());
$myrow = mysql_fetch_row($result);
global $Botname;
$Botname = $myrow[0];

function rgbhex($red, $green, $blue)
{
	return sprintf('#%02X%02X%02X', $red, $green, $blue);
}

function dumppost($ru)
{
	global $botid,$db;
	ob_start();				
	$WebAddress=$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
	$Date=date("r");
	$LoggedInAs=$ru;
	echo "<table>";
	array_walk($_POST,tabline);
	echo "</table><hr>\n";
	$contents=ob_get_contents();
	ob_end_clean();
	$sql = "INSERT INTO log (botid, Date, Username, WebAddress, Action) VALUES('$botid','$Date', '$LoggedInAs','$WebAddress','$contents');";
	$result = mysql_query($sql,$db);
	echo (mysql_error());
}

function dumppost2($ru)
{
	$fp=fopen("postlog.php","a+b");
	if($fp)
	{
		ob_start();				
		echo "<table>\n<tr><td colspan=2>Web address '" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "'</td></tr>\n<tr><td colspan=2>" . date("r") . "</td></tr>\n<tr><td colspan=2>Logged in as user '" . $ru . "'</td></tr>\n";
		array_walk($_POST,tabline);
		echo "</table><hr>\n";
		$contents=ob_get_contents();
		ob_end_clean();
		fwrite($fp,$contents);
		fclose($fp);
	}
}

function tabline($value, $key)
{
	print ("<tr><td>");
	print (htmlspecialchars($key));
	print ("</td><td>");
	print (htmlspecialchars($value));
	print ("</td></tr>\n");
}
?>
